$def with (records)

$var title: $_('SIP Log')
$var page: log
$code:
	snames = gv.snames
	if gv.sd['lg'] == 1:
		log_state = _(u"Enabled")
		log_option = "checked"
	else:
		log_state = _(u"Disabled")
		log_option = ""
		
	def formatTime(t):
		if gv.sd['tf']:
			return t
		else:
			hour = int(t[0:2])
			newhour = hour
			if hour == 0:
				newhour = 12
			if hour > 12:
				newhour = hour-12
			return str(newhour) + t[2:] + (" am" if hour<12 else " pm")


<script>
    // Initialize behaviors
    jQuery(document).ready(function(){
        jQuery("button#nRefresh").click(function(){
            window.location = "/vl";
        });
        jQuery("button#nDeleteAll").click(function(){
            jQuery("form#df").submit();
        });
    });

</script>

<div id="options">
    <div class="title">$_('Log ')$log_state</div>
    <form method="get" action="/cl" name="df" id="df"></form>
</div>

<div id="log">
    <p>$_('Total number of records: ')${len(records)} (${_("no") if gv.sd['lr'] == 0 else gv.sd['lr']}$_(' limit'))</p>
    <p>$_('Download log as ')<a href="/wl">csv</a>.</p>

    <table class="logList">
    	<thead>
        <tr class="log_rec">
            <th>$_('Date')</th>
            <th>$_('Start Time')</th>
            <th>$_('Station')</th>
            <th>$_('Duration')</th>
            <th>$_('Adjustment')</th>
            <th>$_('Program')</th>
        </tr>
        </thead>
         
        <tbody> 
        $ odd = 1
        $for r in records:
            $ event = r #  ast.literal_eval(json.loads(r))
            <tr class="log_rec ${'odd' if odd else 'even'}">
                <td>${event["date"]}</td>
                <td>${formatTime(event["start"])}</td>
                <td>${snames[event["station"]]}</td>
                <td>${event["duration"]}</td>
                $if "adjustment" in r:
                    <td>${event["adjustment"] + " %"}</td>
                $else:
                    <td></td>
                <td>${event["program"]}</td>
            </tr>
            $ odd = 1 - odd
        </tbody>  
    </table>

</div>

<div class="controls">
    <button id="nRefresh" class="refresh">$_('Refresh')</button>
    <button id="nDeleteAll" class="delete danger">$_('Clear Log')</button>
</div>
